import xlwt


class WriteExcel():

    def __init__(self):
        self.workbook = xlwt.Workbook()
        self.sheet = self.workbook.add_sheet('report')

    def write_sheet(self,valuelist,rownum=0,colnum=0):
        '''定义写入sheet中，需要传入起始行数默认0，起始的列数默认为0，和一个二维列表'''
        rows = len(valuelist)#获取要写入的行数
        for row in range(rows):
            cols = len(valuelist[row])#获取要写入的列数
            for col in range(cols):
                write_cell = str(valuelist[row][col])
                if write_cell.isdigit():
                    write_cell = int(write_cell)#字符串是数字就变成整型
                self.sheet.write(row+rownum,col+colnum,write_cell)



    def save_excle(self,exclepath):
        self.workbook.save(exclepath)